<include file="Public/min-header"/>
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content ">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
                <a href="javascript:;" class="btn btn-default" data-url="#" onclick="get_help(this)"><i class="fa fa-question-circle"></i> 帮助</a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 添加广告</h3>
                </div>
                <div class="panel-body " style="padding-bottom: 200px">
                    <!--表单数据-->
                    <form method="post" id="handleposition" action="{:U('Admin/Ad/adHandle')}">
                        <!--通用信息-->
                        <div class="tab-content col-md-10">
                            <div class="tab-pane active" id="tab_tongyong">
                                <div class="tab-pane active" id="tab_tongyong">
                                    <div class="callout callout-inro">

                                        <p>1：首页和积分商城banner广告:支持jpg、jpeg、png格式上传，建议图片750*360、大小1.00M以内的图片。</p>
                                        <p>2：产品分类页面广告:支持jpg、jpeg、png格式上传，建议图片宽度552*180、大小1.00M以内的图片。</p>

                                    </div>
                                </div>
                                <table class="table table-bordered">
                                    <tbody>
                                    <tr>
                                        <td class="col-sm-2">广告名称：</td>
                                        <td class="col-sm-8">
                                            <input type="text" class="form-control" name="ad_name" value="{$info.ad_name|default="自定义广告名称"}" >
                                            <span id="err_attr_name" style="color:#F00; display:none;"></span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>广告类型：</td>
                                        <td>
                                            <select name="media_type" class="input-sm">
                                                <option value="0">图片</option>
                                                <option value="1">flash</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>分部：</td>
                                        <td>
                                          
                                            <volist name='fenbuList' id='vo'>
											<div style="width:150px;height:50px;display:block;margin-right: 10px;float: left;text-align: center;line-height: 50px">
												{$vo.fenbu_name}<input name="fenbu_id[]" <if condition="$vo.status eq 1"> checked="checked"</if>  type="checkbox" value="{$vo.fenbu_id}">
											</div>
										</volist>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>广告位置：</td>
                                        <td>
                                            <select name="pid" class="input-sm pid">
                                                <volist name="position" id="item">
                                                    <option value="{$item.position_id}" <if condition="$info[pid] eq $item[position_id]">selected</if>>{$item.position_name}</option>
                                                </volist>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>开始日期：</td>
                                        <td>
                                            <fieldset>
                                                <div class="control-group">
                                                    <div class="controls">
                                                        <div class="input-prepend input-group">
                                                                <span class="add-on input-group-addon">
                                                                        <i class="glyphicon glyphicon-calendar fa fa-calendar">
                                                                        </i>
                                                                </span>
                                                            <input type="text" style="width: 300px" name="begin" id="start_time" class="form-control" value='{$info.start_time}'>
                                                        </div>
                                                    </div>
                                                </div>
                                            </fieldset>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>结束时间：</td>
                                        <td>
                                            <fieldset>
                                                <div class="control-group">
                                                    <div class="controls">
                                                        <div class="input-prepend input-group">
                                                                    <span class="add-on input-group-addon">
                                                                            <i class="glyphicon glyphicon-calendar fa fa-calendar">
                                                                            </i>
                                                                    </span>
                                                            <input type="text" style="width: 300px" name="end" id="end_time" class="form-control" value='{$info.end_time}'>

                                                        </div>
                                                    </div>
                                                </div>
                                            </fieldset>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>广告链接：</td>
                                        <td>
                                            <!--<input type="text" class="form-control" name="ad_link" value="{$info.ad_link}" >-->
                                            <select name="ad_link" class="ad_link input-sm" style="float: left">
                                                <option value="0">请选择广告链接</option>
                                                <volist name="link" id="value" >
                                                    <option value="{$key}" <if condition="$info.ad_link eq $key">selected</if>>{$value}</option>
                                                </volist>
                                            </select>
                                            <div class="ids" style="float: left">
                                                <if condition="$info.objectId neq null">
                                                    <span style="margin-left: 10px"> Id： <input type="text" style="width: 200px" class="form-control" name="objectId" value="{$info.objectId}" ></span>
                                                </if>
                                            </div>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td>广告图片：</td>
                                        <td>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" style="width:350px;margin-left:-15px;" name="ad_code" id="ad_code" value="{$info.ad_code}" >
                                            </div>
                                            <div class="col-sm-3">
                                                <input type="button" class="btn btn-default" onClick="GetUploadify(1,'ad_code','ad','')"  value="上传图片"/>
                                            </div>
                                        </td>
                                    </tr>

                                    <tr class="bgcolor">
                                        <td>背景颜色：</td>
                                        <td> <input class="form-control" id="bgcolor" name="bgcolor" type="color" value="{$info.bgcolor}" style="width:200px;"/> </td>
                                    </tr>

                                    <tr  style="display:none">
                                        <td>默认排序：</td>
                                        <td>
                                            <input type="text" class="input-sm" id="orderby" name="orderby" value="{$info.orderby}"  placeholder="50">
                                        </td>
                                    </tr>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td><input type="hidden" name="act" value="{$act}">
                                            <input type="hidden" name="ad_id" value="{$info.ad_id}">

                                        </td>
                                        <td class="text-right"><input class="btn btn-primary" type="button" onclick="adsubmit()" value="保存"></td></tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </form><!--表单数据-->
                </div>
            </div>
        </div>
    </section>
</div>
<script>
    function adsubmit(){
        $('#handleposition').submit();
    }

    $(document).ready(function() {

        $(document).on('change','.ad_link',function() {
            var t = $(this);
            var  id = t.val();

            if (id == "/pages/goods_details/goods_details" || id == "/pages/store/index" || id == "/pages/goods/detail/detail" ||　id == "/pages/topic/topic"||　id == "/pages/seller/seller/seller"){
                // t.after('<span style="margin-left: 10px"> Id： <input type="text" style="width: 200px" class="form-control" name="objectId" value="" ></span>')
                $('.ids').html('<span style="margin-left: 10px"> Id： <input type="text" style="width: 200px" class="form-control" name="objectId" value="" ></span>')
            }else{
                $('.ids').html('')
            }


        });



        $('#start_time').daterangepicker({
            format:"YYYY-MM-DD HH:mm",
            singleDatePicker: true,
            showDropdowns: true,
            showWeekNumbers: true,
            timePicker: true,
            timePickerIncrement: 1,
            timePicker12Hour: false,
            opens: 'left',
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-small btn-primary',
            cancelClass: 'btn-small',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        });

        $('#end_time').daterangepicker({
            format:"YYYY-MM-DD HH:mm",
            singleDatePicker: true,
            showDropdowns: true,
            showWeekNumbers: true,
            timePicker: true,
            timePickerIncrement: 1,
            timePicker12Hour: false,
            opens: 'left',
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-small btn-primary',
            cancelClass: 'btn-small',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        });
        var pid = $('.pid').val()
        if(pid == 51342){
            $('.bgcolor').show()
        }else{
            $('.bgcolor').hide()
        }
        $(document).on('change','.pid',function() {
            var t = $(this);
            var  id = t.val();
            console.log(id)


            if (id == 51341){
                console.log(showtime())
                console.log(showtime(2))
                $('#start_time').val(showtime()+' 00:00');
                $('#end_time').val(showtime(2)+" 23:59");
            }
            if(id == 51342){
                $('.bgcolor').show()
            }else{
                $('.bgcolor').hide()
            }


        });
        if(!$('#start_time').val() && !$('#end_time').val()){
            $('#start_time').val(getFirstDay(new Date())+' 00:00');
            $('#end_time').val(getLastDay(new Date())+" 23:59");
        }

    });
    var showtime = function (status) {
        var nowdate = new Date();
        var year = nowdate.getFullYear()
        var month = nowdate.getMonth() + 1
        if(status == 2){
            var date = nowdate.getDate()+1
        }else{
            var date = nowdate.getDate()
        }
        var h = nowdate.getHours(),
            m = nowdate.getMinutes(),
            s = nowdate.getSeconds();
        return year + "-" + month + "-" + date ;
    }
    //当前月最后一天
    function getLastDay(dateObj){
        var y = dateObj.getFullYear(); //获取年份
        var m = dateObj.getMonth() + 1; //获取月份
        var d = new Date(y, m, 0).getDate(); //获取当月最后一日
        m = m < 10 ? '0' + m : m; //月份补 0
        d = d < 10 ? '0' + d : d; //日数补 0
        return [y,m,d].join("-")
    }


    //当前月第一天
    function getFirstDay(dateObj){
        var y = dateObj.getFullYear(); //获取年份
        var m = dateObj.getMonth() + 1; //获取月份
        var d = '01';
        m = m < 10 ? '0' + m : m; //月份补 0
        return [y,m,d].join("-")
    }
</script>
</body>
</html>